import {reqBannerListData,reqFloorListData,reqCategoryListData} from '../../api'


//3.定义方法
const state = {
    categoryList:[],
    bannerList:[],
    floorList:[]
}

const actions = {
     //获取分类列表的action
     async getCategoryListData({commit}){
        const result =await reqCategoryListData()
        //判断业务逻辑是否成功
        if(result.code === 200){
            commit('SAVE_CATEGORY_LIST',result.data)
        }else{
            console.log(result.message);
        }
     },
     
     //获取轮播图中的数据
     async getBannerListData({commit}){
        const result = await reqBannerListData()
        //判断业务是否成功
        if(result.code === 200){
              commit('SAVE_BANNER_LIST',result.data)
        }else{
             console.log(result.message);
        }
     },

     //获取楼层数据
     async getFloorListData({commit}){
          const result = await  reqFloorListData()
          if(result.code === 200){
              commit('SAVE_FLOOR_LIST',result.data)
          }else{
               console.log(result.message);
          }
     }
}

const mutations ={
    //保存分类数据
    SAVE_CATEGORY_LIST(state,payload){
        state.categoryList = payload || []
    },
    //保存轮播图数据
    SAVE_BANNER_LIST(state,payload){
         state.bannerList = payload
    },
    //保存楼层数据
    SAVE_FLOOR_LIST(state,payload){
         state.floorList = payload
    }
}

const getters = {
   
}

//4.导出
export default {
    namespaced:true,
    state,
    actions,
    mutations,
    getters,
}